import React from 'react'
import { Router,Route,Switch } from 'dva/router'
import Authorization from "./routes/Authorization.js"
import CommonLayout from './layouts/CommonLayout.js'
import Login from './routes/login/Login'
import Home from './routes/Home.js'

import {ConfigProvider} from 'antd'


import enUS from 'antd/es/locale/en_US';
import zhCN from 'antd/es/locale/zh_CN';


/**
 * 这里既可以认为是组件也可以认为是函数，history、app是回调函数注入参数而不是使用该组件是作为props传递
 */
export default function RouterConfig({
	history,
	app
}){    
	return (
		<ConfigProvider locale={zhCN}>
			<Router history={history}>
				<Switch>			
					<Route
						path="/login"                    
	                    render={(props)=>{
	                        return (
	                            <CommonLayout>
	                                <Login />
	                            </CommonLayout>
	                        )
	                    }}
					 />					
					<Route
						path="/"					
						render={(props)=>{
							return <Authorization />
	                    }}
	                    exact
					/>	
	                {/* 
	                  * 路由v4不支持<Route>嵌套实现自路由，有两种解决办法：
	                  *     1 直接写一个组件到这里；
	                  *     2 仍然写<Route>不过作为最后一条，由<Switch>制裁上两条成功后不再走此条路由 
	                  *         顺便提一下v4页不支持<IndexRoute>，而<Switch>是新增，用法极其诡异
	                  */}
	                <Route path="/home" component={Home} />
				</Switch>			
			</Router>
		</ConfigProvider>
	)
}